import { Controller } from 'egg';

export default class ChatController extends Controller {
  public async index() {
    const { ctx, service } = this;
    const message = ctx.args[0];
    console.log('chat :', message + ' : ' + process.pid);
    const say = await service.userService.say();
    ctx.socket.emit('res', say);

    ctx.socket.on('index', (data) => {
      console.log(data);
    })
  }

  public async check() {
    const { ctx, service } = this;
    console.log(ctx.socket);
    const message = ctx.args[0];
    console.log('chat :', message + ' : ' + process.pid);
    const say = await service.userService.say();
    ctx.socket.broadcast.emit('res','every body'+say);

    ctx.socket.on('index', (data) => {
      console.log(data);
    })
  }
}